package com.azure.bigstore.service;

import com.azure.bigstore.entity.Order;
import com.azure.bigstore.entity.OrderItem;
import com.azure.bigstore.repository.OrderItemRepoditory;
import com.azure.bigstore.repository.OrderRepoditory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.persistence.Tuple;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by liuhuaibin on 2018/1/23.
 */
@Service
public class OrderItemService {
    @Autowired
    private OrderItemRepoditory orderItemRepoditory;

    /**
     * 获取热门商品的id
     * @return
     */
    public List<Long> getPids(){
        List<Object[]> pid_count = orderItemRepoditory.getHot();
        List<Long> ids = new ArrayList<>();
        for(Object[] one:pid_count){
            //System.out.println(((BigInteger) one[0]).toString()+" ((BigInteger) one[0]).toString()");
            long pid = Long.valueOf(((BigInteger) one[0]).toString());
            ids.add(pid);
        }
        return ids;
    }
    public List<OrderItem> getItemsByOrderid(String oid){
        return orderItemRepoditory.findByOid(Long.valueOf(oid));
    }

    public OrderItem saveOrderItem(OrderItem orderItem){
        return orderItemRepoditory.save(orderItem);
    }
}
